﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.CompositeWeb.Utility;
using Common;

namespace ProjectDan.CRM.Views
{
    public class UploadFilePresenter : Presenter<IUploadFileView>
    {
        private ICRMController _controller;
        
        public UploadFilePresenter([CreateNew] ICRMController controller)
        {
            _controller = controller;
        }

        public override void OnViewLoaded()
        {
            View.SaveUploadedFile += new EventHandler<DataEventArgs<UploadedFile>>(View_SaveUploadedFile);
        }

        void View_SaveUploadedFile(object sender, DataEventArgs<UploadedFile> e)
        {
            var uploadedFile = e.Data;

            var newId = _controller.SaveUploadedFile(uploadedFile);

            View.CompleteSaveUploadedFile(newId);
        }

        public override void OnViewInitialized()
        {
            // TODO: Implement code that will be executed the first time the view loads
        }

        public void ReleaseView()
        {
            View.SaveUploadedFile -= View_SaveUploadedFile;
        }

        // TODO: Handle other view events and set state in the view
    }
}




